package com.dick.base.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dick.base.aop.OperateLog;
import com.dick.base.model.BusinessCustomer;
import com.dick.base.parameter.CustomerParameter;
import com.dick.base.service.CustomerService;
import com.dick.base.util.BaseResult;
import com.dick.base.util.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 客户接口
 */
@RestController
@RequestMapping("api/customers")
public class CustomerApi {

    private static final String TAG = "客户";

    @Autowired
    private CustomerService customerService;

    @ApiOperation(value = "新增和修改", tags = TAG)
    @OperateLog(operate = "增改客户",
            detail = "T(String).format('id:%d,name:%s,nickname:%s', #parameter?.id, #parameter?.name, #parameter?.nickname)")
    @PostMapping
    public BaseResult<Void> saveCustomer(@RequestBody @Valid CustomerParameter parameter) {
        customerService.saveCustomer(parameter);
        return BaseResult.voidResult();
    }

    @ApiOperation(value = "分页查询", tags = TAG)
    @GetMapping()
    public BaseResult<Page<BusinessCustomer>> customerPage(BusinessCustomer customer, PageInfo pageInfo) {
        return BaseResult.of(customerService.customerPage(customer, pageInfo));
    }

    @ApiOperation(value = "全部列表", tags = TAG)
    @GetMapping("list")
    public BaseResult<List<BusinessCustomer>> customerList() {
        return BaseResult.of(customerService.customerList());
    }
}
